/*
    13. Write a program in C to encrypt a text file. 

    Assume that, the content of the file test.txt is  :                                                                       
    Welcome to w3resource.com. 
    Test Data :
    Input the name of file to encrypt : test.txt
    Expected Output :

    File test.txt successfully encrypted ..!!
    If you read the file test.txt you will see the following :

    ������Ʉ�ӄۗ�������ɒ��ђn
*/

#include <stdio.h>

int main(void)
{
    char fname[64];
    FILE *fp1, *fp2;
    char ch;
    printf("Input the name of file to encrypt : ");
    gets(fname);
    fp1 = fopen(fname, "r");
    if(!fp1){
        printf("Open file %s error!", fname);
        return -1;
    }
    fp2 = fopen("tmp.txt", "w+");
    if(!fp2){
        printf("Open file tmp.txt error!");
        return -1;
    }
    while((ch = fgetc(fp1)) != EOF){
        fputc(ch + 99, fp2);
    }
    fclose(fp1);
    fclose(fp2);

    remove(fname);
    rename("tmp.txt", fname);

    printf("File test.txt successfully encrypted ..!!\n");

    return 0;
}